import { POST } from '../axios.config.js'
import { downloadFile } from '../api'

const base = window.config.ip
const moduleName = 'rcdg-zbkh'

const perform = `${base}/${moduleName}/perform`
const fileHandle = `${base}/xn-supervise/file`

const URLS = {
  getReportViewContent: `${perform}/getReportViewContent`,
  updateReportViewContent: `${perform}/updateReportViewContent`,
  createReportView: `${fileHandle}/createReportView`,
}

// 获取报告内容
export const getReportContent = viewId => POST(URLS.getReportViewContent, { viewId })

// 修改报告内容
export const modifyReportContent = ({ id = '', content = '' }) =>
  POST(URLS.updateReportViewContent, {
    id,
    content,
  })
// 下载报告
export const downloadReport = async id => {
  const res = await POST(URLS.createReportView, {
    id,
  })
  if (res.status === 200) {
    const resData = res.data
    if (resData.sourcePath) {
      downloadFile(resData.id)
    } else {
      throw new Error('暂无报告！')
    }
  }
}
